package com.school.campus.service.impl;

import java.util.List;

import com.school.common.utils.DateUtils;
import com.school.common.utils.RandomStringGeneratorUtils;
import com.school.common.utils.SecurityUtils;
import com.school.common.utils.uuid.IdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.school.campus.mapper.VendingMachineMapper;
import com.school.campus.domain.VendingMachine;
import com.school.campus.service.IVendingMachineService;

/**
 * 自动售货机Service业务层处理
 *
 * @author wwj
 * @date 2025-11-04
 */
@Service
public class VendingMachineServiceImpl implements IVendingMachineService {
    @Autowired
    private VendingMachineMapper vendingMachineMapper;

    /**
     * 查询自动售货机
     *
     * @param id 自动售货机主键
     * @return 自动售货机
     */
    @Override
    public VendingMachine selectVendingMachineById(Long id) {
        return vendingMachineMapper.selectVendingMachineById(id);
    }

    /**
     * 查询自动售货机列表
     *
     * @param vendingMachine 自动售货机
     * @return 自动售货机
     */
    @Override
    public List<VendingMachine> selectVendingMachineList(VendingMachine vendingMachine) {
        return vendingMachineMapper.selectVendingMachineList(vendingMachine);
    }

    /**
     * 新增自动售货机
     *
     * @param vendingMachine 自动售货机
     * @return 结果
     */
    @Override
    public int insertVendingMachine(VendingMachine vendingMachine) {

        vendingMachine.setCode(RandomStringGeneratorUtils.generate6DigitRandomString());
        vendingMachine.setStatus(0L);

        vendingMachine.setCurrentCapacity(0L);
        vendingMachine.setCreateTime(DateUtils.getNowDate());
        return vendingMachineMapper.insertVendingMachine(vendingMachine);
    }

    /**
     * 修改自动售货机
     *
     * @param vendingMachine 自动售货机
     * @return 结果
     */
    @Override
    public int updateVendingMachine(VendingMachine vendingMachine) {
        return vendingMachineMapper.updateVendingMachine(vendingMachine);
    }

    /**
     * 批量删除自动售货机
     *
     * @param ids 需要删除的自动售货机主键
     * @return 结果
     */
    @Override
    public int deleteVendingMachineByIds(Long[] ids) {
        return vendingMachineMapper.deleteVendingMachineByIds(ids);
    }

    /**
     * 删除自动售货机信息
     *
     * @param id 自动售货机主键
     * @return 结果
     */
    @Override
    public int deleteVendingMachineById(Long id) {
        return vendingMachineMapper.deleteVendingMachineById(id);
    }
}
